# -*- coding:utf-8 -*-
from heuristics.sqr_min import *
from heuristics.Obst_Distance import *
from search.all import *
from multi_robot_problem import MultiRobotState
from time import *
from problem_generator import ProblemGenerator
"""
Created on Apr 11, 2011

@author: bob
"""
 
height, width = 10,10
minRobs, maxRobs = 3,5
difficulty = ProblemGenerator.HARD
minPiles, maxPiles, minObs, maxObs = 3, 5, 3, 7 
minWallLength, maxWallLength = 6,8
pGen = ProblemGenerator(height, width, minRobs, maxRobs, difficulty,
    minPiles, maxPiles, minObs, maxObs, minWallLength, maxWallLength)

width, height = 14, 13
robots =  ((13, 5), (12, 4), (11, 3), (0, 2))
piles =  frozenset([(4, 10), (6, 9), (12, 12), (10, 11), (9, 8), (10, 6), (1, 4), (2, 10), (12, 9), (1, 2), (12, 2), (7, 0), (12, 0), (8, 1), (6, 1), (5, 7), (7, 4), (9, 2), (0, 11), (9, 11), (5, 0), (2, 2), (0, 9), (12, 3), (8, 4)])
obstacles =  frozenset([(7, 3), (8, 3), (2, 6), (3, 1), (6, 11), (8, 11), (9, 3), (3, 2), (10, 12), (6, 3), (0, 6), (9, 4), (4, 5), (9, 5), (11, 12)])
#obstacles = frozenset()
#problem = MultiRobotState(width, height, robots, piles, obstacles)
problem = pGen.trollProblem()

filename = "C:\\Users\\bob\\Desktop\\ai\\problems.txt"
FILE = open(filename,"a")
FILE.write("\n"+str(asctime())+"\n")
FILE.write("size:"+str((problem.width,problem.height)))
FILE.write("robots:"+str(problem.robots))
FILE.write("obstacles:"+str(problem.obstacle_locations))
FILE.write("piles:"+str(problem.dirt_locations))

print "~~~~~The problem:~~~~~"
print problem
#########################
#h = Pile_Division(problem)
#print h.evaluate(problem)
#########################
gbf = BestFirstGraphSearch()
#astar = AStar()
gbf_any = BestFirstAnyTimeGraphSearch()
sol = gbf_any.find(problem, Pile_Division(problem),40)
if not sol is None:
    print "gbf_any:"+str(len(sol)),sol
    astar_any = AStarAnytime()
    sol = astar_any.find(problem, Pile_Division(problem),40)
    if not sol is None:
        print "astar_any:"+str(len(sol[0].getPathActions())),len(sol[1])
